package com.pro.service.imple;

import com.google.gson.Gson;
import com.pro.mapper.JsCourseRecordMapper;
import com.pro.pojo.JsCourseRecord;
import com.pro.service.JsCourseRecordService;
import com.pro.utils.RedisCache;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class JsCourseRecordServiceImple implements JsCourseRecordService {
    @Autowired
    private JsCourseRecordMapper mapper;

    @Autowired
    private RedisCache redisCache;

    public List<JsCourseRecord> selectProduct(String result,Integer limit,Integer page){
        page = (page-1)*limit;
        List<JsCourseRecord> list = mapper.selectProduct(result,limit,page);
        Gson gson = new Gson();
        redisCache.setCacheObject("RecordSelectProduct",gson.toJson(list));
        return list;
    };
    public Integer countProduct(String result){
        Integer integer = mapper.countProduct(result);
        redisCache.setCacheObject("RecordCountProduct",integer);
        return integer;
    };
    public List<JsCourseRecord> selectThree(String productName,
                                            String title,
                                            String trueName,
                                            Integer limit,
                                            Integer page){
        page = (page-1)*limit;
        List<JsCourseRecord> list = mapper.selectThree(productName, title, trueName,limit,page);
        return list;
    };
    public Integer countThree(String productName,String title,String trueName){
        Integer integer = mapper.countThree(productName, title, trueName);
        return integer;
    };


    public List<JsCourseRecord> selectGaoJi(
                                String productCode,
                                String title,
                                String productName,
                                String currentpriceProduct,
                                String trueName,
                                String result,
                                Integer limit,
                                Integer page){
        page = (page-1)*limit;
        List<JsCourseRecord> list = mapper.selectGaoJi(productCode,title,productName,currentpriceProduct,trueName,result,limit,page);
        return list;
    };
    public Integer countGaoJi(
                              String productCode,
                              String title,
                              String productName,
                              String currentpriceProduct,
                              String trueName,
                              String result){
        Integer integer = mapper.countGaoJi(productCode,title,productName,currentpriceProduct,trueName,result);
        return integer;
    };
    //审核
    public Boolean insertRecord(JsCourseRecord jsCourseRecord){
        Boolean aBoolean = mapper.insertRecord(jsCourseRecord);
        return aBoolean;
    };

    @Override
    public Boolean addJsCourseRecord(JsCourseRecord jsCourseRecord) {
        return mapper.addJsCourseRecord(jsCourseRecord);
    }

    @Override
    public List<JsCourseRecord> getDetailed(Integer productId) {
        return mapper.getDetailed(productId);
    }

    @Override
    public int productRecord() {
        return mapper.productRecord();
    }
}
